﻿-var entity = ViewData["entity"] as Client
-var roles = ViewData["roles"] as List<Role>
-bool popup = ViewData.ContainsKey("popup")
-bool create = (entity.Id == 0)
-bool readOnly = ViewData.ContainsKey("readonly")
-bool isexternal = ViewData.ContainsKey("isexternal")
-bool regdata = ViewData.ContainsKey("regdata")

%form.validate{action="client.ivp/save",method="post",enctype="multipart/form-data"}
  _formfields
  =HTMLHelper.HiddenInput("id",entity.Id)
  #content{class=(popup || isexternal?"popup":"")}
    .formheader
      %h1
        %img.icon24{src="img/headericons/user.gif"}
        -if (regdata)
          Регистрационные данные
        -else
          =(create)?"Новый клиент":String.Format("{0} {1}",entity.LastName,entity.Name)
    _error
    #tabs
      %ul
        %li
          %a#ageneral.selected{href="#",onclick="return setTab('general')"} Общие
        -if(!create && !isexternal && !regdata && !popup)
          %li
            %a#atasks{href="#",onclick="return setTab('tasks')"} Запись на прием
    .formbody
      .tab#general
        .field
          %table{width="630"}
            %tr
              %td{width="210"}            
                .field
                  %label.required{for="lastname"} Фамилия
                  %input#lastname.px200.big.basictext.required{name="lastname",value=HTMLHelper.EscapeQuotes((create && ViewData.ContainsKey("lastname")) ? ViewData["lastname"] as string: entity.LastName),maxlength="100"}
              %td{width="210"} 
                .field
                  %label.required{for="name"} Имя
                  %input#name.px200.big.basictext.required{name="name",value=HTMLHelper.EscapeQuotes(entity.Name),maxlength="100"}
              %td{width="210"} 
                .field
                  %label.required{for="patronymicname"} Отчество
                  %input#patronymicname.px200.big.basictext.required{name="patronymicname",value=HTMLHelper.EscapeQuotes(entity.PatronymicName),maxlength="100"}
        .field
          %table{width="430"}
            %tr
              %td{width="210"}
                .field
                  %label{for="email"} Email
                  %input#email.px200.email{name="email",value=entity.Email,maxlength="100"}
              %td{width="210"}
                .field
                  %label.required{for="phone"} Телефон
                  %table{width="200"}
                    %tr
                      %td{width="10", align="center" }
                        %label.paddedtop2 +7
                      %td{width="5", align="center" }
                        %label.paddedtop2(
                      %td{width="45", align="center" }
                        %input#phone1.px40.required.digits{name="phone1",value=create ? "" : entity.PhonePartsArray[0], minlength="3", maxlength="3", onkeyup="switchTelephoneInput(1);"}
                      %td{width="15", align="center" }
                        %label.paddedtop2)
                      %td{width="45", align="center" }
                        %input#phone2.px40.required.digits{name="phone2",value=create ? "" : entity.PhonePartsArray[1], minlength="3",maxlength="3", onkeyup="switchTelephoneInput(2);"}
                      %td{width="8", align="center" }
                        =(char)45
                      %td{width="45", align="center" }
                        %input#phone3.px40.required.digits{name="phone3",value=create ? "" : entity.PhonePartsArray[2], minlength="2",maxlength="2", onkeyup="switchTelephoneInput(3);"}
                      %td{width="8", align="center" }
                        =(char)45
                      %td{width="45", align="center" }
                        %input#phone4.px40.required.digits{name="phone4",value=create ? "" : entity.PhonePartsArray[3], minlength="2",maxlength="2"}
                    %tr
                      %td{width="10", align="center" }
                      %td{width="5", align="center" }
                      %td{width="45", align="center" }
                        %label 495
                      %td{width="15", align="center" }
                      %td{width="45", align="center" }
                        %label 791
                      %td{width="8", align="center" }
                      %td{width="45", align="center" }
                        %label 45
                      %td{width="8", align="center" }
                      %td{width="45", align="center" }
                        %label 15
        -if(!popup)
          .field
            %label{for="password"} Пароль
            -if( !create )
              #pwdplaceholder
                %a{href="#",onclick="javascript:$('#pwdplaceholder').hide();$('#newpwd').show();$('#password').attr('disabled',false); return false;"} Изменить
              #newpwd.hidden
                %input#password.px200.big.required.login{name="password",disabled="true",maxlength="50"}
            -else
              %input#password.px200.big.login{name="password",maxlength="50"}  
        -if(!popup)
          %div{class=(regdata) ? "field hidden" : "field"}
            %label.radio{for="isactivated"}
              =HTMLHelper.Checkbox("isactivated","True","", entity.IsActivated)
              ="Активирован"
          %div{class=(regdata) ? "field hidden " : "field"}
            %label.radio{for="isarchive"}
              =HTMLHelper.Checkbox("isarchive","True","", entity.IsArchive)
              ="Архивный"
            .details Архивный пользователь не может работать с системой и не может быть использован при создании новых заявок.
          %div{class=(regdata) ? "field hidden " : "field"}
            %label.radio{for="isnotify"}
              =HTMLHelper.Checkbox("isnotify","True","", entity.IsNotify)
              ="Уведомить нотариуса о клиенте"
        -else 
          -if(!entity.IsActivated)
            .field Пользователь не активирован  
          -if(entity.IsArchive)
            .field Пользователь в архиве
          -if(entity.IsNotify)
            .field Уведомить нотариуса о клиенте
        =HTMLHelper.HiddenInput("roleid", 2, "")
        =HTMLHelper.HiddenInput("isexternal",isexternal)
      .tab#tasks                 
    .formbottom
      -if(!readOnly)
        -if (!isexternal && !regdata)
          %button.saveandreturn#submit{type="submit",onclick="$('#returnaftersave').val('true')"} Сохранить и вернуться
        %button.save#submit{type="submit",onclick="$('#returnaftersave').val('')"} Сохранить
      -if(popup)
        %button.return{type="button",onclick="self.close();"} Вернуться
      -else if(isexternal)
        %button.return{type="button",onclick=String.Format("addClient({0})",entity.Id)} Вернуться
      -else if (!regdata)
        %button.return{type="button",onclick="closeForm();"} Вернуться
        
